﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Transform;

namespace ScheduleMaker.DB
{
    public class LevelDAO : AbstractDAO<LevelDAO>
    {

        public Level getByName(string name)
        {
            createSession();
            ICriteria criteria = session.CreateCriteria(typeof(Level))
                .Add(Restrictions.Eq("Name", name)).SetResultTransformer(new DistinctRootEntityResultTransformer());
            IList<Level> users = criteria.List<Level>();
            closeSession();
            if (users.Count > 0)
            {
                return users.ElementAt<Level>(0);
            }
            else
            {
                return null;
            }
        }

    }
}
